﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using COM.OA.Entity;
using COM.OA.BLL;
using System.Collections.Generic;

public partial class rlzy_daxg : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        users loginuser = Session["loginuser"] as users;
        if (loginuser == null)
        {
            this.Response.Write(string.Format(GetRedirect.ALLREDIRECT, "../login.aspx"));
        }
        else
        {
            if (!IsPostBack)
            {
                string id = this.Request["id"];
                string where = "em_id =" + id;
                string name = null;
                IList<employee> ilist = employeeBLL.Select(where);
                List<employee> l = (List<employee>)ilist;
                employee em = new employee();
                em = l[0];
                name = em.em_name;

                this.txtNumber.Text = em.em_number;//编号
                this.txtName.Text = em.em_name;//姓名
                this.txtEverName.Text = em.em_evername;//曾用名
                this.ddGender.SelectedIndex = em.em_gender;//性别

                if (em.em_birth.ToString("yyyy-MM-dd").Equals("1753-01-01"))
                {
                    this.wdBirth.Text = "";
                }
                else
                {
                    this.wdBirth.Text = em.em_birth.ToString("yyyy-MM-dd");//出生日期
                }

                this.txtMarriage.Text = em.em_marriage;//婚姻状况
                this.ddNative.SelectedIndex = em.em_n_id - 1;//籍 贯
                this.ddProvince.SelectedIndex = em.em_p_id - 1;//户口所在地
                this.ddNation.SelectedIndex = em.em_na_id - 1;//民族
                this.txtStature.Text = em.em_stature;//身 高
                this.txtAvoirdupois.Text = em.em_avoirdupois;//体重
                this.ddVisage.SelectedIndex = em.em_v_id - 1;//政治面貌
                this.txtStatuscard.Text = em.em_statuscard;//身份证号
                this.txtHealth.Text = em.em_health;//健康状况
                this.txtBloodtype.SelectedIndex = Int32.Parse(em.em_bloodtype);//血型
                this.txtPhone.Text = em.em_phone;//目前电话
                this.txtMobile.Text = em.em_mobile;//手机
                this.txtEMail.Text = em.em_email;//邮箱
                this.txtFinishSchool.Text = em.em_finishschool;//毕业院校
                this.txtSpeciality.Text = em.em_speciality;//专业
                this.ddLearn.SelectedIndex = em.em_l_id - 1;//学历
                if (em.em_graduatetime.ToString("yyyy-MM-dd").Equals("1753-01-01"))
                {
                    this.wdGraduatetime.Text = "";
                }
                else
                {
                    this.wdGraduatetime.Text = em.em_graduatetime.ToString("yyyy-MM-dd");//毕业日期
                }

                this.txtDegree.Text = em.em_degree;//学位
                this.txtLanguage.Text = em.em_language;//外语语种
                this.txtLanguageLevel.Text = em.em_languagelevel;//外语水平
                this.txtLanguageLetter.Text = em.em_languageletter;//外语证书
                this.txtComputerLevel.Text = em.em_computerlevel;//计算机水平
                this.txtComputerLetter.Text = em.em_computerletter;//计算机证书
                this.txtComputerGood.Text = em.em_computergood; //计算机特长
                this.txtMandarinLevel.Text = em.em_mandarinlevel;//普通话水平
                this.txtFamilyaddress.Text = em.em_familyaddress;//家庭住址
                this.txtPostalcode.Text = em.em_postalcode; //邮编
                this.txtAddress.Text = em.em_address;//现住址
                this.txtFamilyPhone.Text = em.em_familyphone;//家庭电话
                this.txtAddresspostalcode.Text = em.em_addresspostalcode;//住址邮编
                this.txtFamilycircs.Text = em.em_familycircs;//家庭情况
                this.txtRecordLocus.Text = em.em_recordlocus;//档案存放地
                this.txtJobName.Text = em.em_jobname;//职称
                this.txtWhenJoinWork.Text = em.em_whenjoinwork;//何时参加工作
                this.txtWhenThisWork.Text = em.em_whenthiswork;//何时到本单位
                this.txtAddlEngth.Text = em.em_addlength;//累计工龄
                this.txtThisUnitLength.Text = em.em_thisunitlength;//本单位工龄
                int bumen = em.em_dept_id - 1;
                if (em.em_dept_id == 6)
                {
                    bumen = bumen - 1;
                }
                else if (em.em_dept_id > 7 && em.em_dept_id <= 9)
                {
                    bumen = bumen - 2;
                }
                else if(em.em_dept_id >= 11)
                {
                    bumen = bumen - 3;
                }

                this.ddDepartment.SelectedIndex = bumen;//所在部门
                this.txtButy.Text = em.em_duty;//职务
                this.txtRemark.Text = em.em_remark;//备注
                //录入人
                int lrid = em.em_bookerid;
                string ww = "u_id=" + lrid;
                IList<users> ii = usersBLL.Select(ww);
                List<users> ll = (List<users>)ii;
                users us = new users();
                us = ll[0];
                int u_em_id = us.u_em_id;
                string wheres = "em_id=" + u_em_id;
                IList<employee> iii = employeeBLL.Select(wheres);
                List<employee> lll = (List<employee>)iii;
                employee employee = new employee();
                employee = lll[0];
                string Bookerid = employee.em_name;

                this.txtBookerid.Text = Bookerid;
            }
        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {

        //取页面数据
        int em_id = Int32.Parse(this.Request["id"]);
        string Number = this.txtNumber.Text;//编号 
        string Name = this.txtName.Text;//姓名
        string EverName = this.txtEverName.Text;//曾用名
        int Gender = Int32.Parse(this.ddGender.Text);//性别
        string Marriage = this.txtMarriage.Text;//婚姻状况
        int Native = Int32.Parse(this.ddNative.Text);//籍贯
        int Province = Int32.Parse(this.ddProvince.Text);//户口所在地
        int Nation = Int32.Parse(this.ddNation.Text);//民族 
        DateTime Birth;//出生日期
        string bi = this.wdBirth.Text;
        if (bi == "")
        {
            Birth = DateTime.Parse("1753-01-01");
        }
        else
        {
            Birth = DateTime.Parse(this.wdBirth.Text);
        } 
        string Stature = this.txtStature.Text;//身高 
        string Avoirdupois = this.txtAvoirdupois.Text;//体重 
        int Visage = Int32.Parse(this.ddVisage.Text);//政治面貌
        string Statuscard = this.txtStatuscard.Text;//身份证号
        string Health = this.txtHealth.Text;//健康状况
        string Bloodtype = this.txtBloodtype.Text;//血型
        string Phone = this.txtPhone.Text;//目前电话
        string Mobile = this.txtMobile.Text;//手机
        string eMail = this.txtEMail.Text;//邮箱
        string FinishSchool = this.txtFinishSchool.Text;//毕业学校
        string Speciality = this.txtSpeciality.Text;//专业
        int Learn = Int32.Parse(this.ddLearn.Text);//学历
        DateTime Graduatetime;//毕业日期
        string t = this.wdGraduatetime.Text;
        if (t == "")
        {
            Graduatetime = DateTime.Parse("1753-01-01");
        }
        else
        {
            Graduatetime = DateTime.Parse(this.wdGraduatetime.Text);
        }
        string Degree = this.txtDegree.Text; //学位
        string Language = this.txtLanguage.Text;//外语语种
        string LanguageLevel = this.txtLanguageLevel.Text;//外语水平
        string LanguageLetter = this.txtLanguageLetter.Text;//外语证书
        string ComputerLevel = this.txtComputerLevel.Text;//计算机水平
        string ComputerLetter = this.txtComputerLetter.Text;//计算机证书
        string ComputerGood = this.txtComputerGood.Text; //计算机特长
        string MandarinLevel = this.txtMandarinLevel.Text;//普通话水平
        string Familyaddress = this.txtFamilyaddress.Text;//家庭住址
        string Postalcode = this.txtPostalcode.Text; //邮编
        string Address = this.txtAddress.Text;//现住址
        string FamilyPhone = this.txtFamilyPhone.Text;//家庭电话
        string Addresspostalcode = this.txtAddresspostalcode.Text;//住址邮编
        string Familycircs = this.txtFamilycircs.Text;//家庭情况
        string RecordLocus = this.txtRecordLocus.Text;//档案存放地
        string JobName = this.txtJobName.Text;//职称
        string WhenJoinWork = this.txtWhenJoinWork.Text;//何时参加工作
        string WhenThisWork = this.txtWhenThisWork.Text;//何时到本单位
        string Addlength = this.txtAddlEngth.Text;//累计工龄
        string ThisUnitLength = this.txtThisUnitLength.Text;//本单位工龄
        int Department = Int32.Parse(this.ddDepartment.Text);//所在部门
        string Buty = this.txtButy.Text;//职务
        string Remark = this.txtRemark.Text;//备注
        DateTime Registertime = DateTime.Now;//录入时间


        employee em = new employee();
        em.em_id = em_id;
        em.em_number = Number;
        em.em_name = Name;
        em.em_evername = EverName;
        em.em_gender = Gender;
        em.em_marriage = Marriage;
        em.em_birth = Birth;
        em.em_n_id = Native;
        em.em_na_id = Nation;
        em.em_p_id = Province;
        em.em_stature = Stature;
        em.em_avoirdupois = Avoirdupois;
        em.em_v_id = Visage;
        em.em_statuscard = Statuscard;
        em.em_health = Health;
        em.em_bloodtype = Bloodtype;
        em.em_phone = Phone;
        em.em_mobile = Mobile;
        em.em_email = eMail;
        em.em_finishschool = FinishSchool;
        em.em_speciality = Speciality;
        em.em_l_id = Learn;
        em.em_graduatetime = Graduatetime;
        em.em_degree = Degree;
        em.em_language = Language;
        em.em_languageletter = LanguageLetter;
        em.em_languagelevel = LanguageLevel;
        em.em_computerlevel = ComputerLevel;
        em.em_computerletter = ComputerLetter;
        em.em_computergood = ComputerGood;
        em.em_mandarinlevel = MandarinLevel;
        em.em_familyaddress = Familyaddress;
        em.em_postalcode = Postalcode;
        em.em_address = Address;
        em.em_familyphone = FamilyPhone;
        em.em_familyaddress = Familyaddress;
        em.em_familyphone = FamilyPhone;
        em.em_addresspostalcode = Addresspostalcode;
        em.em_familycircs = Familycircs;
        em.em_recordlocus = RecordLocus;
        em.em_jobname = JobName;
        em.em_whenjoinwork = WhenJoinWork;
        em.em_whenthiswork = WhenThisWork;
        em.em_addlength = Addlength;
        em.em_thisunitlength = ThisUnitLength;
        em.em_dept_id = Department;
        em.em_duty = Buty;
        em.em_remark = Remark;
        users luser = Session["loginuser"] as users;
        em.em_bookerid = luser.u_id;//录入人id  当前登录用户
        em.em_registertime = DateTime.Now;
        //em.em_photo =   照片

        int i = employeeBLL.Update(em);
        if (i < 0)
        {
            //修改 users 表中 该人部门id
            //通过em_id 查users 表中 此人信息
            string wheres = "u_em_id=" + em_id;
            IList<users> ilist = usersBLL.Select(wheres);
            List<users> l = (List<users>)ilist;
            users user = l[0];
            user.u_dept_id = Department;
            usersBLL.Update(user);

            this.Response.Write(string.Format(GetRedirect.WINALERT, "修改成功!"));
            this.Response.Write(string.Format(GetRedirect.REDIRECT, "dagl.aspx"));
        }
        else
        {
            this.Response.Write(string.Format(GetRedirect.WINALERT, "修改失败请从新修改!"));
        }


    }

}
